Question: 1 -
Which statement is true?public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
-
Compilation fails.
-
"odd" will always be output.
-
"even" will always be output.
-
"odd" will be output for odd values of x, and "even" for even values.
Answer:
Compilation fails.
Solution:
The compiler will complain because of incompatible types (line 4), the if expects a boolean but it gets an integer.
The compiler will complain because of incompatible types (line 4), the if expects a boolean but it gets an integer.
Question: 2 -
What will be the output of the following code snippet?+int a=15;
int b=25;
if ((a < b ) || ( a = 5)>15)
system.out.println(a);
else
system.out.println(b);
-
No output
-
Error
-
15
-
25
Answer:
15
Solution not available.
Question: 3 -
Which statement is true?public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}
-
There is a syntax error on line 1.
-
There are syntax errors on lines 1 and 6.
-
There are syntax errors on lines 1, 6, and 8.
-
There is a syntax error on line 6.
Answer:
There is a syntax error on line 6.
Solution not available.
Question: 4 -
Which two are acceptable types for x?switch(x)
{
default:
System.out.println("Hello");
}
-
short
-
char
-
float
-
long
Answer:
short
Solution not available.
Question: 5 -
What will be the output of the program?int x, y;
x=15; y=20;
if (x>15)
if(y>15)
{
system.ptintln("y is "+y);
}
else
system.out.ptintln("x is "+x);
-
No output
-
x is 15
-
Error
-
y is 20
Answer:
x is 15